import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_button.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_card.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_item.dart';
import 'logic.dart';

class AutonymExpressPage extends StatefulWidget {
  const AutonymExpressPage({Key? key}) : super(key: key);

  @override
  State<AutonymExpressPage> createState() => _AutonymExpressPageState();
}

class _AutonymExpressPageState extends State<AutonymExpressPage> {
  final AutonymExpressLogic logic = Get.put(AutonymExpressLogic());
  final FocusNode _focusNode = FocusNode();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(navigationTitle: "实名认证"),
      body: MGCard(
        margin: EdgeInsets.all(12),
        nodeList: [_focusNode],
        children: [
          MGItems(
            leadTitle: "快递公司",
            trailingWidget: _createTextField(
              hintText: "请选择快递公司",
              controller: logic.expressController,
              enable: false,
            ),
            action: logic.selectExpressList,
          ),
          MGItems(
            leadTitle: "工号",
            trailingWidget: _createTextField(
              hintText: "请输入工号",
              controller: logic.numberController,
              node: _focusNode,
            ),
          )
        ],
      ),
      bottomNavigationBar: Obx(() => MGButton(
            title: "下一步",
            enable: logic.enable.value,
            padding: EdgeInsets.only(left: 20, right: 20, bottom: 35, top: 20),
            buttonAction: logic.bindExpress,
          )),
    );
  }

  /*
  * 创建输入框
  * */
  Widget _createTextField({String? hintText, TextEditingController? controller, FocusNode? node, bool? enable}) {
    TextField field = TextField(
      controller: controller,
      textAlign: TextAlign.end,
      keyboardType: TextInputType.number,
      focusNode: node,
      enabled: enable,
      decoration: InputDecoration(
        hintText: hintText,
        hintStyle: TextStyle(
          fontSize: MGFont.textFont2,
          color: MGColors.text3Color,
        ),
        enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
        disabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
        focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
      ),
    );
    return Expanded(
        child: Container(
      child: field,
      height: 30,
    ));
  }

  @override
  void dispose() {
    Get.delete<AutonymExpressLogic>();
    super.dispose();
  }
}
